<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者，助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
// +----------------------------------------------------------------------
// | Wdadmin系统产品软件并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
// +----------------------------------------------------------------------
namespace app\api\controller\wddj\marketing;
use app\api\model\wddj\User;
use app\common\controller\Api;

/**
 * Class Coupon
 * Desc  优惠券控制器
 * Create on 2025/4/28 15:41
 * Create by wangyafang
 */
class Coupon extends Api
{
    protected $noNeedLogin = ['index'];
    protected $noNeedRight = ['*'];

    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\api\model\wddj\marketing\Coupon();
    }

    /**
     * Desc 优惠券列表
     * Create on 2025/4/28 15:44
     * Create by wangyafang
     */
    public function index(){
        if(!$this->request->isGet()) {
            $this->error('请求类型错误');
        }

        $where = array();
        if ($this->auth->isLogin()) {
            $couponReceiveModel = new \app\api\model\wddj\marketing\CouponReceive();
            $wechat_id = User::getWechatId($this->auth->id);
            $coupon_id_array = $couponReceiveModel->where('wechat_id',$wechat_id)->column('coupon_id');
            $where['id'] = array('not in',$coupon_id_array);
        }

        $data = $this->model
            ->where($where)
            ->field('id,name,discount_price')
            ->where('status','normal')
            ->limit(3)
            ->order('weigh desc,id desc')
            ->select();

        $this->success('请求成功',$data);
    }
}



 